//
//  MainViewController.m
//  UI08_导航控制器
//
//  Created by Scott on 15/4/28.
//  Copyright (c) 2015年 www.lanou3g.com 蓝欧3G. All rights reserved.
//

#import "MainViewController.h"
#import "SecondViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    /* 设置显示标题 */
    self.title = @"系统信息";
    
    /* 设置背景颜色 */
    self.view.backgroundColor = [UIColor whiteColor];
    
#pragma mark - 知识点2 定制 UINavigationBar
/**
 * @brief navigationBar 导航条
    iOS7之后默认是透明的
 *
 * UINavigationController的ContentView里始终显示栈顶控制器的view.
 * viewControllers 属性存储了栈中的所有被管理的控制器
 * navigationController 属性, 父类中的属性, 每个在栈中的控制器, 都能通过此属性, 获取自己所在的UINavigationController对象
 * navigationBar 在透明情况, 与contentView会重合一部分区域
 * navigationBar 在不透明情况下, contentView跟在navigationBar的下面
 * navigationBar 竖屏高度 44, 横屏高度 32
 *
 */
    /* 设置透明度 */
    self.navigationController.navigationBar.translucent = YES;
    
    /* 导航条背景颜色 */
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    
    /* 导航条上项目和按钮颜色 */
    self.navigationController.navigationBar.tintColor = [UIColor redColor];
    
    /* 隐藏导航条 */
    self.navigationController.navigationBarHidden = YES;
    self.navigationController.navigationBarHidden = NO;
    
    /* 导航条 背景添加照片 
     * bar透明度为NO的时候, 图片大小原始大小
     */

//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"1.jpg"] forBarMetrics:UIBarMetricsDefault];
    
    
    /* 取消掉scrollView 的系统UIEdgeInsets */
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(20, 100, 50, 40);
    [button setTitle:@"下一页" forState:UIControlStateNormal];
    [self.view addSubview:button];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
#pragma mark - 知识点4 UINavigationItem
/**
 * @brief UINavigationItem
 *
 * UINavigationBar 除了能自定义自身的样式外, 还管理一组UINavigationItem
 * 与UINavigationController相似,UINavigationBar也是以栈的方式管理一组UINavigationItem. 提供push和pop操作item.
 *
 * 每个视图控制器都有一个navigationItem属性, navigationItem中设置的左按钮, 右按钮, 标题等, 会随着控制的显示, 也显示到navigationBar上
 *
 * UINavigationItem 属于MVC中的M. 封装了要显示在UINavigationBar上的数据
    title   标题
    titleView   标题视图
    leftBarButtonItem   左按钮
    rightBarButtonItem  右按钮
 */
    self.navigationItem.title = @"首页";
    
    /* 将任意一个View作为title */
    self.navigationItem.titleView = [[[UISegmentedControl alloc] initWithItems:@[@"11", @"22"]] autorelease];

    /* 左侧按键 */
    self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemDone) target:self action:@selector(clicked:)] autorelease];
    
    /* 右侧按键 */
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"yu.png"] style:UIBarButtonItemStylePlain target:self action:@selector(rightClick:)] autorelease];
    
    /* 将左边返回键隐藏 */
    self.navigationItem.hidesBackButton = YES;
    
    /**/
    
    
    /* UIBarButtonItem 
     *
     * @ brief UIBarButtonItem属于MVC中的M. 定义了UINavigationItem上按钮的触发事件,外观等.
     
     * 常用的API:
     initWithBarButtonSystemItem:target:action:
     initWithTitle:style:target:action:
     initWithImage:style:target:action:
     tintColor
     */
    
}

- (void)rightClick:(UIBarButtonItem *)right
{
    NSLog(@"右键");
}

- (void)clicked:(UIBarButtonItem *)left
{
    NSLog(@"点击");
}

- (void)buttonClicked:(UIButton *)button
{
#pragma mark - 知识点3 UINavigationController 入栈和出栈
    /* 点击Button 入栈一个新的viweController */
    
    /* 1. 创建一个新的viewController */
    SecondViewController *second = [[SecondViewController alloc] init];
    
    /* 2. push 方法进入下一个viewController */
    [self.navigationController pushViewController:second animated:YES];
    
    
    [second release];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
